package com.tiankong.android.wallpaper.bean;

import java.io.File;
import com.tiankong.android.wallpaper.io.WallPaperIO;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;

public abstract class ImageBean {
	private String path = "";
	private int width = 200;
	private int height = 200;
	private Bitmap image = null;
	private String fileName="";
	private String description="";
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ImageBean(String description,String path, String fileName,int width,int height) {
		this.description=description;
		this.path = path;
		this.width=width;
		this.height=height;		
		this.fileName=fileName;
		
		loadFile(fileName);
	}

	public boolean loadFile(String fileName) {

//		ÎÄ¼þÂ·¾¶ÊÇ·ñ¼ÓÔØ³É¹¦
		if(new WallPaperIO().DirInit(new File(path))){
//			ÎÄ¼þÊÇ·ñ´æÔÚ
			if((image=BitmapFactory.decodeFile(path+fileName))==null){
//				Èç¹û²»´æÔÚ ´´½¨Ò»¸öÎ»Í¼ ²¢±£´æ 
				image=Bitmap.createBitmap(width, height,
						Bitmap.Config.ARGB_8888);
				createDefaultImage(new Canvas(image),new Paint());
				save(image,path+fileName);			
			}
			this.width=image.getWidth();
			this.height=image.getHeight();
			return true;
		}	
		return false;			
	}
	
	public boolean save(Bitmap image,String path) {
		 return new WallPaperIO().saveImage(image, path);
	}
// ³éÏó·½·¨ Éú³ÉÄ¬ÈÏÍ¼Æ¬
	public abstract void createDefaultImage(Canvas c,Paint p);
	

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public Bitmap getImage() {
		return image;
	}

	public void setImage(Bitmap image) {
		this.image = image;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	//google提醒我说很长时间没来访问了
	
}
